using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace shfa.snomtastic.data
{
    public partial class SqlDataProvider
    {

        public Guid InsertSubnet(Guid configurationId, string iP, string mask, string startIP, string endIP, long startInt, long endInt)
		{
            return new Guid(Convert.ToString(SqlHelper.ExecuteScalar(ConnectionString, "sp_SubnetInsert", GetNull(configurationId), iP, mask, startIP, endIP, startInt, endInt)));
		}

        public int UpdateSubnet(Guid subnetId, Guid configurationId, string iP, string mask, string startIP, string endIP, long startInt, long endInt)
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_SubnetUpdate", GetNull(subnetId), GetNull(configurationId), iP, mask, startIP, endIP, startInt, endInt));
		}

        public int DeleteSubnet(Guid subnetId) 
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_SubnetDelete", subnetId));
		}

        public DataRow SelectSubnet(Guid subnetId) 
        {    
			DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_SubnetSelect", subnetId);
            if (ds.Tables.Count > 0)
                if (ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0];

            return null;
		}

		public DataTable SelectSubnets() 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_SubnetSelectAll").Tables[0];
        }

		public DataTable SelectSubnetsByConfiguration(Guid configurationId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_SubnetSelectByConfiguration", configurationId).Tables[0];
        }

    }

}
